package com.example.shopp_2301.adapter

import android.widget.RatingBar
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Comment
import com.example.shopp_2301.R
import com.example.shopp_2301.utils.GlideUtils
import okhttp3.internal.wait

class CommentApdater:BaseQuickAdapter<Comment,BaseViewHolder>(R.layout.item_comment) {
    override fun convert(holder: BaseViewHolder, item: Comment) {
        GlideUtils.loadCircleImage(context,item.avatar,holder.getView(R.id.comment_image))
        holder.setText(R.id.comment_name,item.nickname)
        holder.getView<RatingBar>(R.id.comment_rb).rating = item.score.toFloat()
        holder.setText(R.id.comment_time,item.createTime)
        holder.setText(R.id.comment_msg,item.comment)
        //显示rv的图片
        //找到rv
        val rv = holder.getView<RecyclerView>(R.id.comment_rv)
        //定义适配器
        val imgAdapter = ImgAdapter()
        //给适配器添加数据
        imgAdapter.data.addAll(item.pics)
        //绑定到rv上，设置布局
        rv.adapter = imgAdapter
        rv.layoutManager = GridLayoutManager(context,3)
    }
}

//创建当前item中rv的适配器
class ImgAdapter:BaseQuickAdapter<String,BaseViewHolder>(R.layout.item_img){
    override fun convert(holder: BaseViewHolder, item: String) {
        GlideUtils.loadImage(context,item,holder.getView(R.id.img))
    }

}